<template>
	<view class="">
		<!-- 头部标题 -->
		<view class="cu-bar bg-white">
			<view class="action sub-title">
				<text class="text-xl text-bold text-green">批改作业</text>
				<text class="bg-green"></text>
				<!-- last-child选择器-->
			</view>
		</view>
		<!-- 头部标题 end -->
		
		<!-- 作业内容 -->
		<view class="bg-white padding" style="width: 100%;display: flex;justify-content: space-around;">
			
			<image @click.native="ViewImage" v-for="(item,index) in imgList" :key="index" :src="apiweb +  imgList[index]" style="height: 150upx;width: 150upx;"></image>
			
		</view>
		<!-- end -->
		
		<!-- 评分 -->
		<view class="cu-form-group ">
			<view class="title">评分：</view>
			<picker @change="PickerChange" :value="index" :range="picker">
				<view class="picker">
					{{index>-1?picker[index]:'禁止换行，超出容器部分会以 ... 方式截断'}}
				</view>
			</picker>
		</view>
		<!-- end -->
		
		<view class="padding-xl">
			<button  @click.native="make()" class="cu-btn block bg-gradual-green margin-tb-sm lg">
				<text :class="  statusButton ? 'cuIconfont-spin cuIcon-loading2' : 'cuIconfont-spin' "></text> {{statusButton ? '批改中...' : '批改'}}
				</button>
		</view>
			
		</view>
		
	</view>
</template>

<script>
	var _this;
	export default{
		data(){
			return{
				apiweb:"http://39.96.88.209:8080",
				index:0,//评分下标
				picker:["A+","A","B","C"],//评分
				imgList:[],//图片
				classId:"",//课堂id
				statusButton:false,//按钮状态(是否正在提交中...)
				preview:[],//预览图片
				uid:"",//学生id
				workId:""//作业id
			}
		},
		methods:{
			//预览图片
			ViewImage(e) {
				uni.previewImage({
					urls:  _this.preview,
					current: e.currentTarget.dataset.url
				});
			},
			
			//评分
			PickerChange(e) {
				this.index = e.detail.value
			},
			
			// 批改作业
			make(){
				
				if(_this.statusButton){
					return;
				}
				
				var scroe;
				var picker =  _this.picker[_this.index];
				if(picker == "A+"){
					scroe = 5;
				}else if(picker == "A"){
					scroe = 4;
				}else if(picker == "B"){
					scroe = 3;
				}else if(picker == "C"){
					scroe = 2;
				}
				
				_this.statusButton = true //开启上传
				uni.request({
					url:_this.api + "work/score",
					method:"POST",
					header:{
						"content-type":"application/x-www-form-urlencoded"
					},
					data:{
						workId:_this.workId,
						uid:_this.uid,
						score:scroe
					},
					success: (res) => {
						
					_this.statusButton = false //关闭
						uni.showToast({
							title:"成功！",
							duration:1000,
							icon:"success"
						})
					},
					fail: (err) => {
						uni.showToast({
							title:"请稍后在试!网络异常~~",
							duration:1000,
							icon:"none"
						})
					}
				})
			}
		},
		onLoad(optin) {
			_this = this;
			var listImage = optin.listImage.split(',');
			for(var i = 0;i<listImage.length;i++){
				_this.preview.push(_this.apiweb + listImage[i])
			}
			_this.imgList = listImage;
			_this.uid = optin.uid;
			_this.workId = optin.workId;
			
		}
	}
</script>

<style>
</style>
